﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AzureDriveUI
{
	public static class FileSystemHelper
	{
		private static string _driveLetters = "CDEFGHIJKLMNOPQRSTUVWXYZ";

		public static IEnumerable<string> GetAllAvailableDriveLetters()
		{
			var drivesInUse = DriveInfo.GetDrives()
				.Where(item => item.Name != null && item.Name.Length > 0)
				.Select(item => item.Name[0])
				.ToList();

			foreach (var letter in _driveLetters)
			{
				if (drivesInUse.Contains(letter) == false)
				{
					yield return letter.ToString();
				}
			}
		}

		public static string GetNextAvailableDriveLetter()
		{
			var drivesInUse = DriveInfo.GetDrives()
				.Where(item => item.Name != null && item.Name.Length > 0)
				.Select(item => item.Name[0])
				.ToList();

			foreach (var letter in _driveLetters)
			{
				if (drivesInUse.Contains(letter) == false)
				{
					return letter.ToString();
				}
			}

			return null;
		}
	}
}
